package com.cn.crmsystem.service.customerService.impl;

import com.cn.crmsystem.mapper.customerMapper.CareMapper;
import com.cn.crmsystem.pojo.Care;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.User;
import com.cn.crmsystem.service.customerService.CareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CareServiceImpl implements CareService {

    @Autowired
    private CareMapper careMapper;
    @Override
    public ResultJson insertCare(Care care, Login login) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("care",care);
        map.put("login",login);
        if(careMapper.insertCare(map)>0){
            return new ResultJson<>().getSuccess("添加成功");
        }else{
            return new ResultJson<>().getSuccess("添加失败");
        }
    }


    @Override
    public ResultJson deleteCare(Integer id) {
        if(careMapper.deleteCare(id)>0){
            return new ResultJson<>().getSuccess("删除成功");
        }else{
            return new ResultJson<>().getSuccess("删除失败");
        }
    }

    @Override
    public ResultJson updateCare(Care care) {
        if(careMapper.updateCare(care)>0){
            return new ResultJson<>().getSuccess("修改成功");
        }else{
            return new ResultJson<>().getSuccess("修改失败");
        }
    }

    @Override
    public ResultJson updateCareUser(Integer id) {
        if(careMapper.updateCareUser(id)>0){
            return new ResultJson<>().getSuccess("修改成功");
        }else{
            return new ResultJson<>().getSuccess("修改失败");
        }
    }

    @Override
    public ResultJson<List> selectCare(Map<String, Object> map) {
        List list =careMapper.selectCare(map);
        Long count=careMapper.selectCareCount(map);
        if(list!=null && list.size()>0){
            return new ResultJson<>().getSuccess("查询成功",list,count);
        }else{
            return new ResultJson<>().getSuccess("查询失败");
        }
    }

    @Override
    public ResultJson deleteAllCare(Integer[] ids) {
        int result=0;
        for(int i=0;i<ids.length;i++){
            result=careMapper.deleteCare(ids[i]);
        }
        if(result>0){
            return new ResultJson<>().getSuccess("删除成功");
        }else{
            return new ResultJson<>().getSuccess("删除失败");
        }
    }
}
